import $mAssetsPath from '@/config/assets.config.js'

export default {
	baseURL: 'http://localhost:8080/red_system_war_exploded',

	login(data) {
		uni.setStorageSync('token', data.token)
		uni.setStorageSync('userInfo', data.userInfo)
	},

	logOut() {
		uni.removeStorageSync("token")
		uni.removeStorageSync("userInfo")
	},

	isLogin() {
		return uni.getStorageSync('token') != ''
	},

	headImg() {
		let img = uni.getStorageSync('userInfo').headImg
		if (img != undefined && img != null) {
			return 'http://localhost:8080/red_system_war_exploded' + img + "?random=" + Math.random()
		}
		return $mAssetsPath.headImg
	},

	userInfo() {
		return uni.getStorageSync('userInfo')
	},

	// 代理 uni.request 携带 token 发送请求
	request(status) {
		if (status.header == undefined) {
			status.header = {}
		}
		status.header.token = uni.getStorageSync('token')
		return uni.request(status)
	},

	uploadFile(setting) {
		if (setting.header == undefined) {
			setting.header = {}
		}
		setting.header.token = uni.getStorageSync('token')
		uni.uploadFile(setting)
	}
}
